<?php
$isReloadable = true;
require_once("../../pers/inc.config.php");
require_once(R2_FS_WEB_ROOT.'/app/_inc/inc.session.php');
require_once(R2_FS_WEB_ROOT.'/app/_inc/funct.html.php');

$aWhere = array();
if (reqVar('pagifilt')!='') {
	$aWhere[] = " (s.descr LIKE '%".addslashes(reqVar('pagifilt'))."%') ";
}
$sWhere = (count($aWhere)==0)? "":" WHERE ".implode(" AND ",$aWhere);

$sql_sel = "SELECT count(*) AS num_rec FROM stato s " .$sWhere;
$objDB->query($sql_sel,'selRec');
$acRec = $objDB->fetch('selRec');
$numRec = $acRec['num_rec'];

$link = $_SERVER['PHP_SELF']."?".$sXSNQS;

$startOffset = 0;
$endOffset   = 0;
$sFiltro  = rint2GetFiltro($link);
$sPaginaz = rint2GetPaginaz($link, $numRec, $startOffset, $endOffset);

$sql_sel = " SELECT s.* FROM stato s ".$sWhere
	." ORDER BY s.stato LIMIT "
	.$startOffset.",".($endOffset-$startOffset);
$objDB->query($sql_sel,'selRec');
//dbg_($sql_sel);

$cmdL = "";
if ($objSess->abilitaz['gesstaz'] == 'W') {
	$cmdL .= "<a class=\"cmd1\" href=\"tipiRintMod.php?$sXSNQS\">tipi rint</a>";
	$cmdL .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	$cmdL .= "<a class=\"cmd1\" href=\"prioritaMod.php?$sXSNQS\">priorita'</a>";
	$cmdL .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	$cmdL .= "<a class=\"cmd1\" href=\"tipiAttMod.php?$sXSNQS\">tipi attivita'</a>";
	$cmdL .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
}
$cmdR = "";
if ($objSess->abilitaz['gesstaz'] == 'W') {
	$cmdR .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	$cmdR .= "<a class=\"cmd1\" href=\"stazIns.php?$sXSNQS\">nuovo stato</a>";
}
$cmdR .= cmdTorna(); 

$aTestim['ric'] = 'Richiedente';
$aTestim['ope'] = 'Operatore';
$aTestim['chiuso'] = 'Chiuso';
$aPallini['verde'] = 'Verde';
$aPallini['rosso'] = 'Rosso';
$aPallini['giallo'] = 'Giallo';
$aPallini['bianco'] = 'Bianco';
$aSiNo['S'] = "Si'";
$aSiNo['N'] = "No";
$aSiNo['C'] = "Chiuso";

$aMenuPag = array();
include("./_inc/inc.aMenuPag.php");
testaHtml('Lista Stati', $msgPag, '30.10.10', $aMenuPag);

echo getHtmlForm();
echo getHtmlHidden('xsn',XSN);
echo getHtmlHidden('startoffset');
?>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left"><?=$cmdL?></td>
      <td class="cmd1" align="right"><?=$cmdR?></td>
   </tr>
   <tr>
      <td class="cmd1" align="left"><?=$sFiltro?></td>
      <td class="cmd1" align="right"><?=$sPaginaz?></td>
   </tr>
</table>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="tit1" colspan='11' align='center'>Lista Stati</td>
   </tr>
   <tr>
      <td class="lab1" width='' align='center'>Stato</td>
      <td class="lab1" width='' align='center'>Descrizione</td>
      <td class="lab1" width='' align='center'>Testimone</td>
      <td class="lab1" width='' align='center'>Stati prov.</td>
      <td class="lab1" width='' align='center'>Stati dest.</td>
      <td class="lab1" width='' align='center'>Pallino</td>
      <td class="lab1" width='' align='center'>Abilita stima</td>
      <td class="lab1" width='' align='center'>Abilita assegna</td>
      <td class="lab1" width='' align='center'>Valutata</td>      
      <td class="lab1" width='' align='center'>Evasa</td>
      <td class="lab1" width='' align='center'>Installata</td>
   </tr>
<? 
$clRF = 'txt2';
while ($acSt = $objDB->fetch('selRec')) { 
	$clRF = ($clRF=='txt1')?'txt2':'txt1';	
	$sStyle = '';
	$sqlSel = " SELECT a.stato_fin ". 
	          	" FROM stato_azione a ".
					" WHERE a.stato = ".$acSt['stato'].
	          	" ORDER BY a.stato_fin";
	$objDB->query($sqlSel,'selStX');
	$aSX = array();
	while ($aCX = $objDB->fetch('selStX')) {
		$aSX[] = $aCX['stato_fin'];
	}
	$sStatiFin = implode(',',$aSX);
	$sqlSel = " SELECT a.stato ". 
	          	" FROM stato_azione a ".
					" WHERE a.stato_fin = ".$acSt['stato'].
	          	" ORDER BY a.stato";
	$objDB->query($sqlSel,'selStX');
	$aSX = array();
	while ($aCX = $objDB->fetch('selStX')) {
		$aSX[] = $aCX['stato'];
	}
	$sStatiProv = implode(',',$aSX);
?>
   <tr>
      <td class="<?=$clRF?>" align="center" style='<?=$sStyle?>'>
	      <a href='stazView.php?stato=<?=$acSt['stato']."&$sXSNQS"?>' class="<?=$clRF?>" style='font-family:lucida console,courier;'>
	      	<?=$acSt['stato'];?>
	      </a>
      </td>
      <td class="<?=$clRF?>" align="left" style='<?=$sStyle?>'>
	      <a href='stazView.php?stato=<?=$acSt['stato']."&$sXSNQS"?>' class="<?=$clRF?>">
	      	<?=$acSt['descr'];?>
	      </a>
      </td>
      <td class="<?=$clRF?>" align="center" style='<?=$sStyle?>'><?=$aTestim[$acSt['testimone']];?></td>
      <td class="<?=$clRF?>" align="left" style='<?=$sStyle?>'><?=$sStatiProv;?></td>
      <td class="<?=$clRF?>" align="left" style='<?=$sStyle?>'><?=$sStatiFin;?></td>
      <td class="<?=$clRF?>" align="center" style='<?=$sStyle?>'><?=$aPallini[$acSt['pallino']];?></td>
      <td class="<?=$clRF?>" align="center" style='<?=$sStyle?>'><?=$aSiNo[$acSt['abilita_assegna']];?></td>
      <td class="<?=$clRF?>" align="center" style='<?=$sStyle?>'><?=$aSiNo[$acSt['abilita_stima']];?></td>
      <td class="<?=$clRF?>" align="center" style='<?=$sStyle?>'><?=$aSiNo[$acSt['valutata']];?></td>
      <td class="<?=$clRF?>" align="center" style='<?=$sStyle?>'><?=$aSiNo[$acSt['evasa']];?></td>
      <td class="<?=$clRF?>" align="center" style='<?=$sStyle?>'><?=$aSiNo[$acSt['installata']];?></td>
   </tr>
<? 
} 
?>
</table>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">&nbsp;</td>
      <td class="cmd1" align="right"><?=$sPaginaz?></td>
   </tr>
   <tr>
      <td class="cmd1" align="left"><?=$cmdL?></td>
      <td class="cmd1" align="right"><?=$cmdR?></td>
   </tr>
</table>
<?
echo "</form>";

codaHtml();
exit();
?>

